<?php
	include('db_connection.php');	
	$select = "SELECT * FROM tbl_trainee_schedule WHERE trainer_id='".$_POST['trainer_id']."' AND date(schedule_date)=date('".$_POST['query']."')";
	$query = mysql_query($select) or die(mysql_error());
	
	if(mysql_num_rows($query)>0){
		$results = array();
		while($row = mysql_fetch_array($query)){
			
			$select_user_sch = "SELECT * FROM tbl_user_sel_sch_time WHERE trainer_id='".$row['trainer_id']."' AND course_id='".$_POST['course_id']."' AND date(sch_date)=date('".$_POST['query']."') AND time_slot_id = '".$row['time_slot_id']."'";

			$query_user_sch = mysql_query($select_user_sch) or die(mysql_error());
			if(mysql_num_rows($query_user_sch)>0){
													
			}else{
				$select_slot = "SELECT * FROM tbl_timeslot WHERE id = '".$row['time_slot_id']."'";  
				$query_slot = mysql_query($select_slot) or die(mysql_error());
				
				if(mysql_num_rows($query_slot)>0){
					while($row_slot = mysql_fetch_array($query_slot)){
						$result['course_slot'] = $row_slot['course_slot'];
					}
				}
				
				$result['id'] = $row['id'];
				$result['trainer_id'] = $row['trainer_id'];
				$result['time_slot_id'] = $row['time_slot_id'];
				$result['schedule_date'] = $row['schedule_date'];
				$results[] = $result;
			}
		}		
		echo json_encode($results);//return $results;    
		
	}
		
?>